<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <!-- 引入axios -->
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
    <!-- 引入Vue -->
    <script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>

</head>

<body>
    <div>
        <center>
            <h1>注册页面</h1>
            <input type="text" v-model="user.username" placeholder="用户名"><br>
            <input type="text" v-model="user.password" placeholder="密码"><br>
            <input type="text" v-model="user.nickname" placeholder="昵称"><br>
            <input type="button" value="注册" @click="reg()">
        </center>
    </div>
    <script>
        let v = new Vue({
            el: "body>div",
            data: {
                // 创建用户对象
                user:{
                    username:"",
                    password:"",
                    nickname:""
                }
            },
            methods: {
                reg(){
                    // 发送post请求
                    axios.post("/reg",v.user).then(function (response){
                        // 判断是否注册成功,1为成功,0为的为失败
                        if (response.data==1){
                            alert("注册成功!");
                            location.href="/login.html" // 跳转到首页
                        }else {
                            alert("用户名已存在!")
                        }

                    })
                }
            }
        })
    </script>
</body>

</html>